package whr.modules.assessment.service.impl;

import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import whr.common.utils.PageUtils;
import whr.common.utils.Query;

import whr.modules.assessment.dao.AssessmentDao;
import whr.modules.assessment.entity.AssessmentEntity;
import whr.modules.assessment.service.AssessmentService;


@Service("assessmentService")
public class AssessmentServiceImpl extends ServiceImpl<AssessmentDao, AssessmentEntity> implements AssessmentService {
    @Autowired
    private AssessmentDao assessmentDao;
    @Autowired
    private AssessmentService assessmentService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        // 获取分页信息
        IPage<AssessmentEntity> page = new Query<AssessmentEntity>().getPage(params);

        // 创建查询条件包装器
        QueryWrapper<AssessmentEntity> queryWrapper = new QueryWrapper<>();

        // 从 params 中提取 year 和 quarter 参数
        String year = (String) params.get("year");
        String quarter = (String) params.get("quarter");
        String name = (String) params.get("key");

        // 添加 year 和 quarter 查询条件
        if (year != null && !year.isEmpty()) {
            queryWrapper.eq("year", year);
        }
        if (quarter != null && !quarter.isEmpty()) {
            queryWrapper.eq("quarter", quarter);
        }
        if (name != null && !name.isEmpty()) {
            queryWrapper.like("employee_name", name);
        }
        // 执行分页查询
        page = this.page(page, queryWrapper);
        return new PageUtils(page);
    }

    @Override
    public List<AssessmentEntity> getPerformancesByYearAndQuarter(int year, String quarter) {
        return assessmentDao.getPerformancesByYearAndQuarter(year, quarter);
    }

    @Override
    public List<Integer> getYear() {
        List<Integer> years = assessmentDao.getYear();
        return years;
    }


}